from time import sleep

from selenium.webdriver.common.by import By

from util.Util import BoxDriver, BasePage


class Login(BasePage):

    def login(self,username="admin",passwd="123456"):
        self.driver.clear(By.ID,'account')
        self.driver.input(By.ID,'account',username)
        self.driver.clear(By.ID,'password')
        self.driver.input(By.ID,'password',passwd)
        self.driver.click(By.ID, 'submit')

    def getrealname(self):
        # 获取登录后的用户名，如果登录失败则为“”
        sleep(2)
        name = ""
        names = self.driver.find_elements(By.XPATH,'//*[@id="mainNavbar"]/div/ul[1]/li/a')
        if len(name) > 0:
            name = names[0].text

        return name

    def assertlogin(self,username,expect_name):
        # 对登录后的用户名和期待的用户名进行对比
        assert username == expect_name

    def signput(self):
        # 签退操作
        self.driver.find_element_by_link_text("签退")

    def confirm(self):
        # 登录失败点击确认按钮
        self.driver.click(By.LINK_TEXT, "确认")


if __name__ == '__main__':
    driver = BoxDriver('Chrome')
    login =  Login(driver)
    login.login('admin','123456')
    login.signput()